{% extends 'base.html' %}
{% load custom_filters %}

{% block title %}测试用例分组 - EasyTesting{% endblock %}

{% block header %}
    {% if project %}
        测试用例分组 - {{ project.name }}
    {% else %}
        全部测试用例分组
    {% endif %}
{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    {% if project %}
                        <a href="{% url 'project_detail' pk=project.id %}" class="btn btn-outline-secondary me-2">
                            <i class="bi bi-arrow-left"></i> 返回项目
                        </a>
                    {% endif %}
                </div>
                <div>
                    {% if project %}
                        <a href="{% url 'test_case_group_create' %}?project={{ project.id }}" class="btn btn-primary">
                            <i class="bi bi-folder-plus"></i> 新增用例分组
                        </a>
                        <a href="{% url 'test_case_create' %}?project={{ project.id }}" class="btn btn-success ms-2">
                            <i class="bi bi-plus-circle"></i> 新增测试用例
                        </a>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    {% if project %}
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header bg-light">
                        <h5 class="card-title mb-0">
                            <i class="bi bi-folder2-open"></i> 测试用例分组树
                        </h5>
                    </div>
                    <div class="card-body">
                        {% if root_groups %}
                            <div class="group-tree">
                                {% for group in root_groups %}
                                    {% include 'test_manager/partials/test_case_group_tree_item.html' with group=group level=0 %}
                                {% endfor %}
                            </div>
                        {% else %}
                            <div class="alert alert-info">
                                <i class="bi bi-info-circle"></i> 没有发现分组，请创建分组
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    {% else %}
        {% if project_groups %}
            {% for project_group in project_groups %}
                <div class="row mt-4">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-header bg-light">
                                <h5 class="card-title mb-0">
                                    <a href="{% url 'project_detail' pk=project_group.project.id %}">
                                        <i class="bi bi-briefcase"></i> {{ project_group.project.name }}
                                    </a>
                                </h5>
                            </div>
                            <div class="card-body">
                                <div class="group-tree">
                                    {% for group in project_group.root_groups %}
                                        {% include 'test_manager/partials/test_case_group_tree_item.html' with group=group level=0 %}
                                    {% endfor %}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            {% endfor %}
        {% else %}
            <div class="text-center py-5">
                    <i class="bi bi-folder display-4 text-muted mb-3"></i>
                    <h5>暂无分组</h5>
                    <p class="text-muted">创建分组来管理测试用例（请创建项目后在项目详情中创建分组）</p>

                </div>
        {% endif %}
    {% endif %}
</div>
{% endblock %}

{% block styles %}
<style>
    .group-tree {
        font-family: var(--bs-font-monospace);
    }
    .group-item {
        padding: 8px 0;
        border-radius: 4px;
        transition: background-color 0.2s;
    }
    .group-item:hover {
        background-color: rgba(0,0,0,0.03);
    }
    .group-name {
        font-weight: 500;
    }
    .group-badge {
        font-size: 0.75rem;
        padding: 2px 6px;
    }
    .group-actions {
        opacity: 0.2;
        transition: opacity 0.2s;
    }
    .group-item:hover .group-actions {
        opacity: 1;
    }
</style>
{% endblock %}
